/**
 * @file    drv_pwm.h
 * @author  yhy
 * @brief   芯必达IM94x系列芯片, pwm抽象层
 * @version 1.01
 * @date    2025-07-14
 *
 * @copyright Copyright (c) 2025
 *
 * @details
 * Change Logs:
 * Date           Author       Notes
 * 2025-07-14     yhy          the first version V1.00
 * 2025-08-04     yhy          新增PWM频率选择 V1.01
 *
 */
#ifndef __DRV_PWM_H__
#define __DRV_PWM_H__

#include "common_config.h"

#include <stdbool.h>
#include <stdint.h>

/**
 * @brief PWM实例
 *
 */
typedef enum
{
    PWM_INSTANCE_SPWM0 = 0U,
    PWM_INSTANCE_SPWM1 = 1U,
    PWM_INSTANCE_SPWM2 = 2U,
    PWM_INSTANCE_IPWM0 = 3U,
    PWM_INSTANCE_IPWM1 = 4U,
    PWM_INSTANCE_MAX
} snf_pwm_instance_e;

/**
 * @brief PWM通道号
 *
 */
typedef enum
{
    PWM_CHANNEL_0 = 0U,
    PWM_CHANNEL_1 = 1U,
    PWM_CHANNEL_2 = 2U,
    PWM_CHANNEL_3 = 3U,
    PWM_CHANNEL_4 = 4U,
    PWM_CHANNEL_5 = 5U,
    PWM_CHANNEL_6 = 6U,
    PWM_CHANNEL_7 = 7U,
    PWM_CHANNEL_MAX
} snf_pwm_channel_e;

/**
 * @brief PWM占空比
 *
 */
typedef enum
{
    PWM_FREQ_20KHZ = 0U, /*!< 占空比20KHZ */
    PWM_FREQ_100HZ = 1U, /*!< 占空比100HZ */
} snf_pwm_freq_e;

/**
 * @brief PWM配置结构体
 *
 */
typedef struct
{
    snf_pwm_instance_e instance;                      /*!< PWM实例 */
    snf_pwm_freq_e     freq;                          /*!< PWM频率 */
    snf_pwm_channel_e  channel_list[PWM_CHANNEL_MAX]; /*!< PWM通道号列表 */
    uint32_t           pin_num_list[PWM_CHANNEL_MAX]; /*!< PWM引脚编号列表 */
    uint8_t            channel_num;                   /*!< PWM注册的通道数量 */
} snf_pwm_config_t;

result_e snf_drv_pwm_init(const snf_pwm_config_t *pwm_config);
result_e snf_drv_pwm_set_duty(snf_pwm_instance_e instance, snf_pwm_channel_e channel, uint8_t duty);

#endif
